home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume20 / epsonps / part01 next >
Encoding:
Text File  |  1991-05-25  |  50.4 KB  |  2,123 lines

  1. Newsgroups: comp.sources.misc
  2. From: Russell Lang <rjl@monu1.cc.monash.edu.au>
  3. Subject:  v20i014:  epsonps - Epson to Postscript converter, Part01/02
  4. Message-ID: <1991May23.144853.20650@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: 1d3e82b1b3c5447c35401d6cd2e059ca
  6. Date: Thu, 23 May 1991 14:48:53 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Russell Lang <rjl@monu1.cc.monash.edu.au>
  10. Posting-number: Volume 20, Issue 14
  11. Archive-name: epsonps/part01
  12.  
  13. The program epsonps converts epson printer codes from an input file 
  14. to PostScript. It is an excellent ASCII listing printer.
  15. Command line options are provided for auto linefeed, auto carriage return, 
  16. condensed mode, elite mode, output file name, IBM screen dump mode 
  17. and paper type selection.
  18.  
  19. It is written in C and will compile and run on MS-DOS and Unix.  
  20. A Unix makefile is provided.  
  21. To compile for MS-DOS see the comments in the Unix makefile.
  22.  
  23. All Epson LX-800 and Star NL-10 codes are recognised except
  24.     1: Download characters <ESC> %, <ESC> &
  25.     2: Alignment <ESC> a
  26.     3: Proportional printing <ESC> p
  27. Most Epson LQ-800 printer codes are recognised.
  28.  
  29. Originally posted as "epson.c" in comp.lang.postscript on 4th March 1988
  30. by Jon Greenblatt with the following copyright message:
  31.  
  32.     Copyright (c) 1988, Jonathan Greenblatt,
  33.         <jonnyg@rover.umd.edu> (128.8.2.73)
  34.         <jonnyg@umd5.umd.edu> (128.8.10.5)
  35.         <pcproj@gymble.umd.edu> (128.8.128.16)
  36.     This program may be redistributed in source form,
  37.     provided no fee is charged and this copyright notice is preserved.
  38.  
  39.     Further contributions by:
  40.        Mark Alexander <uunet!amdahl!drivax!alexande@umd5.UMD.EDU>
  41.  
  42.  
  43. I have expanded the program and renamed it epsonps.c.
  44. The copyright message still applies.
  45.  
  46. Russell Lang <rjl@monu1.cc.monash.edu.au>
  47. Department of Electrical and Computer Systems Engineering
  48. Monash University, Australia
  49. -----
  50. #! /bin/sh
  51. # This is a shell archive.  Remove anything before this line, then unpack
  52. # it by saving it into a file and typing "sh file".  To overwrite existing
  53. # files, type "sh file -c".  You can also feed this as standard input via
  54. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  55. # will see the following message at the end:
  56. #        "End of shell archive."
  57. # Contents:  README epsonps.c
  58. # Wrapped by rjl@monu1 on Thu May 23 10:53:25 1991
  59. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  60. if test -f README -a "${1}" != "-c" ; then 
  61.   echo shar: Will not over-write existing file \"README\"
  62. else
  63. echo shar: Extracting \"README\" \(1339 characters\)
  64. sed "s/^X//" >README <<'END_OF_README'
  65. XThe program epsonps converts epson printer codes from an input file 
  66. Xto PostScript. It is an excellent ASCII listing printer.
  67. XCommand line options are provided for auto linefeed, auto carriage return, 
  68. Xcondensed mode, elite mode, output file name, IBM screen dump mode 
  69. Xand paper type selection.
  70. X
  71. XIt is written in C and will compile and run on MS-DOS and Unix.  
  72. XA Unix makefile is provided.  
  73. XTo compile for MS-DOS see the comments in the Unix makefile.
  74. X
  75. XAll Epson LX-800 and Star NL-10 codes are recognised except
  76. X    1: Download characters <ESC> %, <ESC> &
  77. X    2: Alignment <ESC> a
  78. X    3: Proportional printing <ESC> p
  79. XMost Epson LQ-800 printer codes are recognised.
  80. X
  81. XOriginally posted as "epson.c" in comp.lang.postscript on 4th March 1988
  82. Xby Jon Greenblatt with the following copyright message:
  83. X
  84. X    Copyright (c) 1988, Jonathan Greenblatt,
  85. X        <jonnyg@rover.umd.edu> (128.8.2.73)
  86. X        <jonnyg@umd5.umd.edu> (128.8.10.5)
  87. X        <pcproj@gymble.umd.edu> (128.8.128.16)
  88. X    This program may be redistributed in source form,
  89. X    provided no fee is charged and this copyright notice is preserved.
  90. X
  91. X    Further contributions by:
  92. X       Mark Alexander <uunet!amdahl!drivax!alexande@umd5.UMD.EDU>
  93. X
  94. X
  95. XI have expanded the program and renamed it epsonps.c.
  96. XThe copyright message still applies.
  97. X
  98. XRussell Lang <rjl@monu1.cc.monash.edu.au>
  99. X
  100. END_OF_README
  101. if test 1339 -ne `wc -c <README`; then
  102.     echo shar: \"README\" unpacked with wrong size!
  103. fi
  104. # end of overwriting check
  105. fi
  106. if test -f epsonps.c -a "${1}" != "-c" ; then 
  107.   echo shar: Will not over-write existing file \"epsonps.c\"
  108. else
  109. echo shar: Extracting \"epsonps.c\" \(44784 characters\)
  110. sed "s/^X//" >epsonps.c <<'END_OF_epsonps.c'
  111. X/*
  112. X *  epsonps.c
  113. X *  version 1.00   19910507
  114. X *
  115. X *  IBM Graphics printer to postscript translator.
  116. X *
  117. X *    Copyright (c) 1988, Jonathan Greenblatt,
  118. X *        <jonnyg@rover.umd.edu> (128.8.2.73)
  119. X *        <jonnyg@umd5.umd.edu> (128.8.10.5)
  120. X *        <pcproj@gymble.umd.edu> (128.8.128.16)
  121. X *      This program may be redistributed in source form,
  122. X *      provided no fee is charged and this copyright notice is preserved.
  123. X *
  124. X *  DESCRIPTION:
  125. X *    This program converts epson printer codes from an input file to
  126. X *    PostScript on standard output.  Unknown, ignored or invalid epson
  127. X *    codes are output to standard error output.
  128. X *    This program is an excellent ASCII listing printer.
  129. X *
  130. X *    Usage:
  131. X *      epsonps [-L] -[R] [-c] [-d] [-e] [-lleft_margin] [-ooutfile] [-q] 
  132. X *                [-s] [-tpaper_type] file
  133. X *
  134. X *  FILES:
  135. X *    epsonps.c    This file.
  136. X *    epsonps.pro    PostScript prolog.
  137. X *    epsonps.1    Manual page.
  138. X *    Makefile    Makefile for Unix
  139. X *      README        
  140. X *
  141. X *  SUPPORTS:
  142. X *    All Epson LX-800 and Star NL-10 codes except
  143. X *         1: Download characters <ESC> %, <ESC> &
  144. X *        2: Alignment <ESC> a
  145. X *        3: Proportional printing <ESC> p
  146. X *    Most Epson LQ-800 printer codes.
  147. X *
  148. X *  CONTRIBUTIONS:
  149. X *
  150. X *    The Following was contributed by:
  151. X *         Mark Alexander <uunet!amdahl!drivax!alexande@umd5.UMD.EDU>
  152. X *
  153. X *  - Added 1/72 line-spacing support (ESC-A).  This required changing
  154. X *    the scaling in the Y dimension to 792, so that we have 72 points
  155. X *    per inch in Y, instead of 36.
  156. X *  - Changed the BNDY definition to compute page breaks correctly
  157. X *    when we're right at the page break.
  158. X *  - If variable line spacing is being used to slew past the end
  159. X *    of page, don't reset cy to the top of page; instead, set it
  160. X *    to top of page + n, where n is the position it would have
  161. X *    been on continuous paper in an Epson.
  162. X *  - Allowed spaces to be underlined.
  163. X *  - Added support for emphasized mode.  It's treated exactly
  164. X *    the same way as doublestrike.
  165. X *  - Added support for italics.  Italics-bold hasn't been tested, though.
  166. X *  - Print unknown ESC codes on standard error.
  167. X *  - Allow an optional input filename to specified on the command line.
  168. X *  - Changed the indentation to make it more readable to me; you
  169. X *    may not like my style at all (sorry).
  170. X *
  171. X *
  172. X *  BUGS:
  173. X *    1: Seems to timeout the apple laserwriter when I send large prinouts
  174. X *       through the tty line using no special line control.
  175. X *    2: Underlining works, but the lines chop right through the descenders
  176. X *       on some lower case characters.  I haven't tried to fix this.
  177. X *
  178. X *  CONTRIBUTIONS:
  179. X *
  180. X *    The Following was contributed by:
  181. X *        Russell Lang <rjl@monu1.cc.monash.edu.au>
  182. X *        Graham Holmes <eln127v@monu1.cc.monash.edu.au>
  183. X *        19910507
  184. X *  - Compiles with Turbo C 2.0, Turbo C++ 1.01, MSC 5.10, cc.
  185. X *  - Conforms with PostScript document structuring conventions.
  186. X *  - Input file is now binary, input filename is now required.
  187. X *  - Added output file.
  188. X *  - Added many many "Ignoring ..." warnings.
  189. X *  - Added paper type selection - default is A4  (80 chars * 70 lines).
  190. X *    11" paper type not tested - all laserprinters here are A4!
  191. X *  - Revised font selection.  Most font combinations are valid.
  192. X *  - Corrected horizontal tab spacings.
  193. X *  - Added graphic escapes.
  194. X *  - Added margins, vertical tabs, macro, reset printer.
  195. X *  - Added elite, condensed and enlarged modes.
  196. X *  - Added input options 
  197. X *  - Added 1/216" line spacing (and others).
  198. X *  - Escape codes are a combination of Epson LX-800, Epson LQ-800, 
  199. X *    Star NL-10 and Star NX-1000.  There are probably some incompatiblities.
  200. X *  - Changed to single module source - set.c, set.h included in epsonps.c
  201. X *  - Added IBM extended characters and international character sets.
  202. X *  - Added Epson LQ-800 codes.
  203. X *  - Added literal codes.
  204. X *  - Added IBM screen dump mode.
  205. X */
  206. X
  207. X#include    <stdio.h>
  208. X
  209. Xint debug = 1;        /* Print bad things to stderr */
  210. Xint auto_lf = 0;    /* add line feed after carriage return */
  211. Xint auto_cr = 0;    /* add carriage return after line feed */
  212. Xint paper_type = 0;    /* default paper type a4 = 0, 11" = 4 */
  213. Xint country_num = 0;    /* International character set */
  214. Xint expand_print = 1;    /* print characters in range 0x80-0x9f */
  215. Xint ibm_graphic = 1;    /* print IBM graphic characters in range 0x80-0xff */
  216. Xint lq_mode = 0;    /* 0 = epson lx mode, 1 = epson lq mode */
  217. Xint screendump_mode = 0;/* IBM screen dump mode */
  218. Xchar prolog[] = "epsonps.pro";    /* prolog filename */
  219. X
  220. X#define READBIN "rb"    /* binary read mode for fopen() */
  221. X
  222. X#define INTS_IN_SET    16
  223. Xtypedef unsigned int char_set[INTS_IN_SET];
  224. X
  225. X#ifdef __TURBOC__
  226. X#define ANSI
  227. X#endif
  228. X
  229. X/* prototypes */
  230. X#ifdef ANSI
  231. X#include <string.h>
  232. X#include <stdlib.h>
  233. Xint main(int, char*[]);
  234. Xvoid new_page(void);
  235. Xvoid end_page(void);
  236. Xvoid set_font(void);
  237. Xvoid eject_page(void);
  238. Xvoid check_page(void);
  239. Xvoid clear_set(char_set);
  240. Xint in_set(char_set, unsigned char);
  241. Xvoid str_add_set(char_set, char*);
  242. Xvoid init_sets(void);
  243. Xint get_pointx(int);
  244. Xint get_pointy(int);
  245. Xvoid init_tabs(void);
  246. Xvoid reset_printer(void);
  247. Xvoid pchar(unsigned char);
  248. Xvoid putline(void);
  249. Xvoid newline(void);
  250. Xvoid ignore(char*);
  251. Xvoid invalid(char*);
  252. Xvoid hexout(unsigned char);
  253. Xvoid debug_state(char*, unsigned char);
  254. Xvoid dochar(unsigned char);
  255. Xvoid init_printer(void);
  256. Xvoid set_option(int*, char*);
  257. Xvoid usage(char *);
  258. X#else
  259. Xint strlen();        /* from <string.h> */
  260. Xint strcmp();        /* from <string.h> */
  261. Xchar *strcat();        /* from <string.h> */
  262. Xchar *strcpy();        /* from <string.h> */
  263. Xint atoi();        /* from <stdlib.h> */
  264. Xint exit();        /* from <stdlib.h> */
  265. Xchar *malloc();        /* from <stdlib.h> */
  266. Xvoid new_page();
  267. Xvoid end_page();
  268. Xvoid set_font();
  269. Xvoid eject_page();
  270. Xvoid check_page();
  271. Xvoid clear_set();
  272. Xint in_set();
  273. Xvoid str_add_set();
  274. Xvoid init_sets();
  275. Xint get_pointx();
  276. Xint get_pointy();
  277. Xvoid init_tabs();
  278. Xvoid reset_printer();
  279. Xvoid pchar();
  280. Xvoid putline();
  281. Xvoid newline();
  282. Xvoid ignore();
  283. Xvoid invalid();
  284. Xvoid hexout();
  285. Xvoid debug_state();
  286. Xvoid dochar();
  287. Xvoid init_printer();
  288. Xvoid set_option();
  289. Xvoid usage();
  290. X#endif
  291. X
  292. X
  293. X/* Bounding Boxes */
  294. X#define A4_LLX 22
  295. X#define A4_LLY 16
  296. X#define A4_URX 574
  297. X#define A4_URY 826
  298. X
  299. X/* Letter (11"*8.5") bounding box NOT TESTED 19901123 */
  300. X#define LTR_LLX 22
  301. X#define LTR_LLY 16
  302. X#define LTR_URX 590
  303. X#define LTR_URY 784
  304. X
  305. Xstruct page_format {
  306. X    char *name;
  307. X    int llx,lly,urx,ury;    /* bounding box */
  308. X    int nlines;        /* lines per page */
  309. X    int nchars;        /* number of PICA characers across page */
  310. X    int rotate;        /* rotate output ? */
  311. X};
  312. X
  313. Xstruct page_format page_formats[] = {
  314. X  {"a4",    A4_LLX,A4_LLY,A4_URX,A4_URY,70,80,0},   /* 297mm x 210mm */
  315. X  {"a4-15w",A4_LLX,A4_LLY,A4_URX,A4_URY,66,132,1},  /* 11"*15" -> a4 rotated */
  316. X  {"a4-12", A4_LLX,A4_LLY,A4_URX,A4_URY,72,80,0},   /* 12"*8.5" -> a4 */
  317. X  {"a4-11", A4_LLX,A4_LLY,A4_URX,A4_URY,66,80,0},   /* 11"*8.5" -> a4 */
  318. X  {"11", LTR_LLX,LTR_LLY,LTR_URX,LTR_URY,66,80,0},    /* 11"*8.5" */
  319. X  {"11-15w",LTR_LLX,LTR_LLY,LTR_URX,LTR_URY,66,80,1}, /* 11"*15" -> 8.5"*11" */
  320. X  {(char *)NULL,0,0,0,0,0,0,0}
  321. X};
  322. X
  323. XFILE *infile;
  324. XFILE *outfile;
  325. XFILE *prologfile;
  326. X#define EPSONBUFSIZE 20000
  327. Xchar *buffer;
  328. Xchar *progname;
  329. X
  330. Xint left = 0;        /* left margin (in PICA characters) */
  331. Xint maxx, maxy;
  332. Xint xstart, xstop, ystart, ystop, page_ystop;
  333. X#define YSTART line_space;
  334. X
  335. Xint cx, cy;
  336. Xint point_sizex, point_sizey, line_space;
  337. Xint dotposition;
  338. Xint page;
  339. Xint eight_bit = 0;
  340. Xint lcount;
  341. X
  342. X#define    BNDX    (cx > (xstop - point_sizex))
  343. X#define    BNDY    (cy > ystop)
  344. X
  345. X#define    NUM_TABS    28
  346. Xint tabs[NUM_TABS+1];
  347. Xint tabindex;
  348. X#define    NUM_VTABS    16
  349. X#define NUM_VCHANNELS    8
  350. Xint vtabs[NUM_VCHANNELS][NUM_VTABS+1];
  351. Xint vtabchannel = 0;
  352. Xint vsettabchannel = 0;
  353. X
  354. X#define MACROMAX 32
  355. Xchar macro[MACROMAX+1];
  356. Xint mindex;
  357. X
  358. X/* character sets */
  359. Xchar_set printable_set; /* set of printable chararacters in normal font */
  360. Xchar_set needesc_set;    /* set of characters that need to be \ quoted */
  361. Xchar_set ibmgraph_set;    /* set of IBM graphic characters in ibmgraphfont */
  362. Xchar_set ibmextend_set; /* set of IBM extended characters in normal font */
  363. Xchar *printables =
  364. X" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`,./\\[]=-!@#$%^&*()_+|{}:\"<>?~;'";
  365. Xchar *needesc = "()\\";
  366. Xchar *ibmextend1 =
  367. X    "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217";
  368. Xchar *ibmextend2 =
  369. X    "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\237";
  370. Xchar *ibmextend3 =
  371. X    "\240\241\242\243\244\245\246\247\250\255\256\257";
  372. Xchar *ibmgraph1 =
  373. X    "\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017";
  374. Xchar *ibmgraph2 =
  375. X    "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037";
  376. Xchar *ibmgraph3 =
  377. X    "\177\236\251\252\253\254";
  378. Xchar *ibmgraph4 =
  379. X    "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277";
  380. Xchar *ibmgraph5 =
  381. X    "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317";
  382. Xchar *ibmgraph6 =
  383. X    "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337";
  384. Xchar *ibmgraph7 = 
  385. X    "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357";
  386. Xchar *ibmgraph8 = 
  387. X    "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377";
  388. X
  389. Xchar *font_name[] = {
  390. X    "normalfont","boldfont","italicfont","bolditalicfont","ibmgraphfont"};
  391. Xint font_type = 0;
  392. Xtypedef enum {NORMAL, IBMGRAPH, ITALIC} extend_modes;
  393. Xextend_modes extend_mode = NORMAL;
  394. X
  395. X#define MAX_COUNTRY 12
  396. Xchar *international[] = { 
  397. X    "USA","France","Germany","UnitedKingdom","DenmarkI","Sweden", 
  398. X    "Italy","SpainI","Japan","Norway","DenmarkII","SpainII",
  399. X    "LatinAmerica"};
  400. X
  401. X/* width of fonts in characters per inch */
  402. X#define PICA 10
  403. X#define ELITE 12
  404. X#define FIFTEEN 15
  405. X/* height of font in characters per inch */
  406. X#define FONTHEIGHT 6
  407. X
  408. X/* font variations */
  409. Xint underline = 0;
  410. Xint subscript =  0;
  411. Xint doublewidth = 0;
  412. Xint oneline_doublewidth = 0;
  413. Xint highlight = 0;
  414. Xint emphasize = 0;
  415. Xint italic = 0;
  416. Xint elite = 0;
  417. Xint fifteen = 0;
  418. Xint condensed = 0;
  419. Xint doubleheight = 0;
  420. Xint quadheight = 0;
  421. Xint nlq_mode = 0;
  422. X
  423. X/* graphics */
  424. Xint gcount;
  425. Xint g_dpi;
  426. Xint g_dpi_table[] = {60,120,120,240,80,72,90,180,360};
  427. Xint g_mode;
  428. Xint g_mode_k = 0;
  429. Xint g_mode_l = 1;
  430. Xint g_mode_y = 2;
  431. Xint g_mode_z = 3;
  432. Xint gwidth;
  433. X
  434. X
  435. Xvoid
  436. Xnew_page(void)
  437. X{
  438. X    page++;
  439. X    cx = xstart;
  440. X    cy = ystart;
  441. X    fprintf(outfile,"%%%%Page: %d %d\n",page,page);
  442. X    fputs("/saveobj2 save def\n",outfile);
  443. X    set_font();
  444. X}
  445. X
  446. Xvoid
  447. Xend_page(void)
  448. X{
  449. X    fputs("showpage\nsaveobj2 restore\n",outfile);
  450. X}
  451. X
  452. Xvoid
  453. Xset_font(void)
  454. X{
  455. X    int    boldface;
  456. X
  457. X    boldface = highlight || emphasize;
  458. X
  459. X    font_type = 0;
  460. X    if (italic)
  461. X        font_type |= 2;
  462. X    if (boldface)
  463. X        font_type |= 1;
  464. X    if (extend_mode == ITALIC)
  465. X        font_type |= 2;
  466. X    if (extend_mode == IBMGRAPH)
  467. X        font_type = 4;
  468. X
  469. X    point_sizey = get_pointy(FONTHEIGHT);
  470. X
  471. X    if (elite) {
  472. X        point_sizex = get_pointx(ELITE);
  473. X        fputs("elite ",outfile);
  474. X    }
  475. X    else if (fifteen) {
  476. X        point_sizex = get_pointx(FIFTEEN);
  477. X        fputs("fifteen ",outfile);
  478. X    }
  479. X    else {
  480. X        point_sizex = get_pointx(PICA);
  481. X        fputs("pica ",outfile);
  482. X    }
  483. X    if (condensed) {
  484. X        point_sizex = point_sizex * 3 / 5;
  485. X        fputs("condensed ",outfile);
  486. X    }
  487. X    if (doublewidth || oneline_doublewidth) {
  488. X        point_sizex = point_sizex * 2;
  489. X        fputs("doublewidth ",outfile);
  490. X    }
  491. X    else if (doubleheight) {
  492. X        fputs("doubleheight ",outfile);
  493. X        point_sizex = point_sizex * 2;
  494. X        point_sizey = point_sizey * 2;
  495. X    }
  496. X    else if (quadheight) {
  497. X        fputs("quadheight ",outfile);
  498. X        point_sizex = point_sizex * 4;
  499. X        point_sizey = point_sizey * 4;
  500. X    }
  501. X
  502. X    fprintf(outfile,"%s\n",font_name[font_type]);
  503. X}
  504. X
  505. Xvoid
  506. Xeject_page(void)
  507. X{
  508. X    end_page();
  509. X    new_page();
  510. X}
  511. X
  512. X/* Check if cy has gone past a page boundary, and skip to a new
  513. X * page if necessary.  Set the new y-position not to the top of
  514. X * page, but the point it would have been had this been a real
  515. X * Epson printer with continuous forms.
  516. X */
  517. Xvoid
  518. Xcheck_page(void)
  519. X{
  520. X    int oldcy;
  521. X
  522. X    if (BNDY) {
  523. X        oldcy = cy;
  524. X        eject_page();
  525. X        cy = oldcy - ystop + ystart - YSTART;
  526. X    }
  527. X}
  528. X
  529. Xvoid
  530. Xclear_set(set)
  531. Xchar_set set;
  532. X{
  533. X    int i;
  534. X    for (i = 0; i < INTS_IN_SET; i++) set[i] = 0;
  535. X}
  536. X
  537. Xint
  538. Xin_set(set,c)
  539. Xchar_set set;
  540. Xunsigned char c;
  541. X{
  542. X    c &= 0xff;
  543. X    return ((set[c >> 4] & (1 << (c & 15))) != 0);
  544. X}
  545. X
  546. Xvoid
  547. Xstr_add_set(set,s)
  548. Xchar_set set;
  549. Xchar *s;
  550. X{
  551. X    unsigned char c;
  552. X    while (*s) {
  553. X        c = (unsigned char)*s++;
  554. X        c &= 0xff;
  555. X        set[c >> 4] |= 1 << (c & 15);
  556. X    }
  557. X}
  558. X
  559. Xvoid
  560. Xinit_sets(void)
  561. X{
  562. X    clear_set(printable_set);
  563. X    clear_set(needesc_set);
  564. X    clear_set(ibmextend_set);
  565. X    clear_set(ibmgraph_set);
  566. X    str_add_set(printable_set,printables);
  567. X    str_add_set(needesc_set,needesc);
  568. X    str_add_set(ibmextend_set,ibmextend1);
  569. X    str_add_set(ibmextend_set,ibmextend2);
  570. X    str_add_set(ibmextend_set,ibmextend3);
  571. X    str_add_set(ibmgraph_set,ibmgraph1);
  572. X    str_add_set(ibmgraph_set,ibmgraph2);
  573. X    str_add_set(ibmgraph_set,ibmgraph3);
  574. X    str_add_set(ibmgraph_set,ibmgraph4);
  575. X    str_add_set(ibmgraph_set,ibmgraph5);
  576. X    str_add_set(ibmgraph_set,ibmgraph6);
  577. X    str_add_set(ibmgraph_set,ibmgraph7);
  578. X    str_add_set(ibmgraph_set,ibmgraph8);
  579. X}
  580. X
  581. Xint
  582. Xget_pointx(char_per_inch)
  583. X{
  584. X    if (lq_mode)
  585. X        return(360/char_per_inch);
  586. X    return(240/char_per_inch);
  587. X}
  588. X
  589. Xint
  590. Xget_pointy(char_per_inch)
  591. X{
  592. X    if (lq_mode)
  593. X        return(360/char_per_inch);
  594. X    return(216/char_per_inch);
  595. X}
  596. X
  597. Xvoid
  598. Xinit_tabs(void)
  599. X{
  600. Xint i;
  601. X    for (i=0; i<NUM_TABS; i++)
  602. X        tabs[i] = (i+1) * 8;
  603. X    tabs[NUM_TABS] = -1;
  604. X    for (vtabchannel=0; vtabchannel<NUM_VCHANNELS; vtabchannel++)
  605. X        for (i=0; i<=NUM_VTABS; i++)
  606. X            vtabs[vtabchannel][i] = 0;
  607. X    vtabchannel = 0;
  608. X}
  609. X
  610. Xvoid
  611. Xreset_printer(void)
  612. X{
  613. X    end_page();
  614. X
  615. X    /* margins */
  616. X    left = 0;
  617. X    xstart = left * get_pointx(PICA);
  618. X    xstop = maxx;
  619. X    ystart = YSTART;
  620. X    ystop = maxy;
  621. X    page_ystop = ystop;
  622. X
  623. X    /* line spacing */
  624. X    line_space = get_pointy(FONTHEIGHT);
  625. X
  626. X    /* current position */
  627. X    cx = xstart;
  628. X    cy = ystart;
  629. X
  630. X    /* fonts */
  631. X    font_type = 0;
  632. X    underline = 0;
  633. X    subscript =  0;
  634. X    doublewidth = 0;
  635. X    oneline_doublewidth = 0;
  636. X    highlight = 0;
  637. X    emphasize = 0;
  638. X    italic = 0;
  639. X    elite = 0;
  640. X    fifteen = 0;
  641. X    condensed = 0;
  642. X    doubleheight = 0;
  643. X    quadheight = 0;
  644. X
  645. X    /* graphics */
  646. X    g_mode_k = 0;
  647. X    g_mode_l = 1;
  648. X    g_mode_y = 2;
  649. X    g_mode_z = 3;
  650. X
  651. X    /* tabs */
  652. X    init_tabs();
  653. X
  654. X    /* other */
  655. X    eight_bit = 0;
  656. X    ibm_graphic = 1;
  657. X    expand_print = 1;
  658. X    country_num = 0;
  659. X
  660. X    new_page();
  661. X    fprintf(outfile,"%s InternationalSet\n",international[country_num]);
  662. X}
  663. X
  664. X#define    LINE_SIZE    256
  665. Xunsigned char pline[LINE_SIZE];
  666. Xint ptr = 0;
  667. X
  668. Xchar outline[LINE_SIZE+5];    /* used in putline() and main() */
  669. X
  670. Xvoid
  671. Xpchar(c)
  672. Xunsigned char c;
  673. X{
  674. X    if (eight_bit) {
  675. X        if (eight_bit == 1)
  676. X            c |= 0x80;
  677. X        else
  678. X            c &= 0x7f;
  679. X    }
  680. X    if (in_set(printable_set,c)) {
  681. X        if (extend_mode != NORMAL) {
  682. X            putline();
  683. X            extend_mode = NORMAL;
  684. X            set_font();
  685. X        }
  686. X        pline[ptr++] = c;
  687. X    }
  688. X    else if (ibm_graphic && in_set(ibmextend_set,c)) {
  689. X        if (extend_mode != NORMAL) {
  690. X            putline();
  691. X            extend_mode = NORMAL;
  692. X            set_font();
  693. X        }
  694. X        pline[ptr++] = c;
  695. X    }
  696. X    else if (ibm_graphic && in_set(ibmgraph_set,c)) {
  697. X        if (extend_mode != IBMGRAPH) {
  698. X            putline();
  699. X            extend_mode = IBMGRAPH;
  700. X            set_font();
  701. X        }
  702. X        pline[ptr++] = c;
  703. X    }
  704. X    else if (!ibm_graphic && in_set(printable_set,c&0x7f)) {
  705. X        if (extend_mode != ITALIC) {
  706. X            putline();
  707. X            extend_mode = ITALIC;
  708. X            set_font();
  709. X        }
  710. X        pline[ptr++] = c&0x7f;
  711. X    }
  712. X    else {
  713. X        if (debug)
  714. X            fprintf(stderr,
  715. X              "Character 0x%02x is not printable\n",((int)c)&0xff);
  716. X        if (extend_mode != NORMAL) {
  717. X            putline();
  718. X            extend_mode = NORMAL;
  719. X            set_font();
  720. X        }
  721. X        pline[ptr++] = ' ';
  722. X    }
  723. X}
  724. X
  725. Xvoid
  726. Xputline(void)
  727. X{
  728. X    unsigned char *s = pline;
  729. X    int p;
  730. X    int lx;
  731. X
  732. X    check_page();
  733. X
  734. X    /* Skip over leading spaces, unless underlining is enabled
  735. X     * (we want to underline spaces)
  736. X     */
  737. X    if (underline == 0) {
  738. X        while (*s == ' ' && ptr > 0) {
  739. X        s++;
  740. X        ptr--;
  741. X        if (BNDX) {
  742. X            cx = xstart;
  743. X            newline();
  744. X        }
  745. X        cx += point_sizex;
  746. X        }
  747. X    }
  748. X
  749. X    while (ptr > 0) {
  750. X        p = 0;
  751. X        check_page();
  752. X        if (BNDX) {
  753. X        cx = xstart;
  754. X        newline();
  755. X        }
  756. X        lx = cx;
  757. X        while ((lx+point_sizex-1) < xstop && ptr > 0 && p < LINE_SIZE) {
  758. X        if (*s>0x7f || *s<0x20) {
  759. X            outline[p++] = '\\';
  760. X            (void)sprintf(&outline[p],"%03o",*s++);
  761. X            p+=3;
  762. X        }
  763. X        else {
  764. X            if (in_set(needesc_set,*s))
  765. X                outline[p++] = '\\';
  766. X                outline[p++] = *s++;
  767. X        }
  768. X        ptr--;
  769. X        lx += point_sizex;
  770. X        }
  771. X        outline[p] = 0;
  772. X        if (p > 0) {
  773. X        int i = strlen(outline);
  774. X        /* Forward slash won't work at the end of a string */
  775. X        if (outline[i-1] == '/') {
  776. X            outline[i] = ' ';
  777. X            outline[i+1] = '\0';
  778. X        }
  779. X        if (subscript) {
  780. X          if (subscript == 1) /* Subscript */
  781. X            fprintf(outfile,"%d %d M gsave 1 .5 scale (%s) S grestore\n"
  782. X            ,cx,cy,outline);
  783. X          else   /* Superscript */
  784. X            fprintf(outfile,"%d %d M gsave 1 .5 scale (%s) S grestore\n"
  785. X            ,cx,(cy-(point_sizey>>1)),outline);
  786. X        }
  787. X        else /* Normal printing */
  788. X            fprintf(outfile,"%d %d M (%s) S\n",cx,cy,outline);
  789. X        if (underline)
  790. X            fprintf(outfile,"%d %d M %d %d L stroke\n",
  791. X            cx,cy+3,lx-1,cy+3);
  792. X        }
  793. X        cx = lx;
  794. X    }
  795. X}
  796. X
  797. Xvoid
  798. Xnewline(void)
  799. X{
  800. X    cy += line_space;
  801. X    if (doubleheight)
  802. X        cy += get_pointy(FONTHEIGHT) * 2 / 3;
  803. X    else if (quadheight)
  804. X        cy += get_pointy(FONTHEIGHT) * 2;
  805. X    check_page();
  806. X}
  807. X
  808. Xvoid
  809. Xignore(str)
  810. Xchar *str;
  811. X{
  812. X    if (debug)
  813. X        fprintf(stderr,"Ignoring %s sequence\n",str);
  814. X}
  815. X
  816. Xvoid
  817. Xinvalid(str)
  818. Xchar *str;
  819. X{
  820. X    if (debug)
  821. X        fprintf(stderr,"Invalid %s sequence\n",str);
  822. X}
  823. X
  824. Xchar hextable[] = {'0','1','2','3','4','5','6','7','8','9',
  825. X        'A','B','C','D','E','F'};
  826. X
  827. Xvoid
  828. Xhexout(c)
  829. Xunsigned char c;
  830. X{
  831. X    (void)fputc(hextable[ ((int)c>>4) & 0x0f ],outfile);
  832. X    (void)fputc(hextable[ (int)c & 0x0f ],outfile);
  833. X}
  834. X
  835. Xvoid
  836. Xdebug_state(str,c)
  837. Xchar *str;
  838. Xunsigned char c;
  839. X{
  840. X    if (debug>=2)
  841. X        fprintf(stderr,"%s: 0x%02x %c\n", str, c,
  842. X#ifdef __TURBOC__
  843. X            (c>=32 && c<127) || (c>=128) ? c : ' ');
  844. X#else
  845. X            (c>=32 && c<127) ? c : ' ');
  846. X#endif
  847. X}
  848. X
  849. Xtypedef enum {S_BASE,S_ESC,S_UNDERLINE,S_SUBSCRIPT,S_DOUBLE,S_NLQMODE,
  850. X    S_LINESPACE,S_FINE_LINESPACE,S_LINEFEED,S_REV_LINEFEED,
  851. X    S_IGNORE1,S_IGNORE2,S_IGNORE3,S_MASTER,S_ENLARGE,S_DOUBLEHEIGHT,
  852. X    S_SETTAB,S_SETVTAB1,S_SETVTAB2,S_VTABCHANNEL,S_VSETTABCHANNEL,
  853. X    S_TABINC,S_HTABINC,S_VTABINC,S_SKIP,S_HSKIP,S_VSKIP,
  854. X    S_PAGELENGTH,S_PAGEINCH,S_BOTTOM,S_TOP,S_RIGHT,S_LEFT,
  855. X    S_ABSOLUTE1,S_ABSOLUTE2,S_RELATIVE1,S_RELATIVE2,
  856. X    S_MACRO,S_SETMACRO,S_IBM_MODE,S_INTERNATIONAL,
  857. X    S_LITERAL,S_LITERAL1,S_LITERAL2,S_LITERAL_COUNT,S_SCREENDUMP,
  858. X    S_GRAPHIC_MODE,S_GRAPHIC1,S_GRAPHIC2,S_GRAPHIC,
  859. X    S_DEF_GRAPHIC,S_DEF_K,S_DEF_L,S_DEF_Y,S_DEF_Z,
  860. X    S_GRAPHIC9_MODE,S_GRAPHIC9_1,S_GRAPHIC9_2,
  861. X    S_GRAPHIC9_TOP,S_GRAPHIC9_BOTTOM,S_GRAPHIC24_2, 
  862. X    S_GRAPHIC24_TOP,S_GRAPHIC24_MIDDLE,S_GRAPHIC24_BOTTOM} states;
  863. X
  864. Xstates state = S_BASE;
  865. X
  866. Xvoid
  867. Xdochar(c)
  868. Xunsigned char c;
  869. X{
  870. X    c &= 0xff;
  871. X    if (ptr >= LINE_SIZE) putline();
  872. X    switch (state)
  873. X    {
  874. X    case S_UNDERLINE:
  875. X        debug_state("S_UNDERLINE",c);
  876. X        state = S_BASE;
  877. X        if (c == '\0' || c == '0')    underline = 0;
  878. X        else if (c == '\1' || c == '1')    underline = 1;
  879. X        break;
  880. X    case S_DOUBLE:
  881. X        debug_state("S_DOUBLE",c);
  882. X        state = S_BASE;
  883. X        if (c == '\0' || c == '0')    doublewidth = 0;
  884. X        else if (c == '\1' || c == '1')    doublewidth = 1;
  885. X        set_font();
  886. X        break;
  887. X    case S_SUBSCRIPT:
  888. X        debug_state("S_SUBSCRIPT",c);
  889. X        state = S_BASE;
  890. X        if (c == '\0' || c == '0')    subscript = 2;
  891. X        else if (c == '\1' || c == '1')    subscript = 1;
  892. X        break;
  893. X    case S_NLQMODE:
  894. X        debug_state("S_NLQMODE",c);
  895. X        state = S_BASE;
  896. X        if (c == '\0' || c == '0')    nlq_mode = 0;
  897. X        else if (c == '\1' || c == '1')    nlq_mode = 1;
  898. X        break;
  899. X    case S_LINESPACE:
  900. X        debug_state("S_LINESPACE",c);
  901. X        state = S_BASE;
  902. X        if (lq_mode)
  903. X            line_space = c * get_pointy(60); /* c/60 " */
  904. X        else
  905. X            line_space = 3 * c;         /* c/72 " */
  906. X        break;
  907. X    case S_FINE_LINESPACE:
  908. X        debug_state("S_FINE_LINESPACE",c);
  909. X        state = S_BASE;
  910. X        if (lq_mode)
  911. X            line_space = c * get_pointy(180); /* c/180 " */
  912. X        else
  913. X            line_space = c;             /* c/216 " */
  914. X        break;
  915. X    case S_LINEFEED:
  916. X        debug_state("S_LINEFEED",c);
  917. X        state = S_BASE;
  918. X        if (lq_mode)
  919. X            cy += c * get_pointy(180);
  920. X        else
  921. X            cy += c;
  922. X        break;
  923. X    case S_REV_LINEFEED:
  924. X        debug_state("S_REV_LINEFEED",c);
  925. X        state = S_BASE;
  926. X        if (lq_mode)
  927. X            cy -= c * get_pointy(180);
  928. X        else
  929. X            cy -= c;
  930. X        break;
  931. X    case S_IGNORE1:
  932. X        debug_state("S_IGNORE1",c);
  933. X        state = S_BASE;
  934. X        break;
  935. X    case S_IGNORE2:
  936. X        debug_state("S_IGNORE2",c);
  937. X        state = S_IGNORE1;
  938. X        break;
  939. X    case S_IGNORE3:
  940. X        debug_state("S_IGNORE3",c);
  941. X        state = S_IGNORE2;
  942. X        break;
  943. X    case S_MASTER:
  944. X        debug_state("S_MASTER",c);
  945. X        state = S_BASE;
  946. X        elite = c & 0x01;
  947. X        /* ignore proportional c & 0x02 */
  948. X        condensed = c & 0x04;
  949. X        emphasize = c & 0x08;
  950. X        highlight = c & 0x10;
  951. X        doublewidth = c & 0x20;
  952. X        italic = c & 0x40;
  953. X        underline = c & 0x80;
  954. X        set_font();
  955. X        break;
  956. X    case S_ENLARGE:
  957. X        debug_state("S_ENLARGE",c);
  958. X        state = S_BASE;
  959. X        switch(c) {
  960. X            case 0:
  961. X                doubleheight = 0;
  962. X                quadheight = 0;
  963. X                set_font();
  964. X                break;
  965. X            case 1:
  966. X                doubleheight = 1;
  967. X                quadheight = 0;
  968. X                cy += get_pointy(FONTHEIGHT) * 2 / 3;
  969. X                set_font();
  970. X                break;
  971. X            case 2:
  972. X                doubleheight = 0;
  973. X                quadheight = 1;
  974. X                cy += get_pointy(FONTHEIGHT) * 2;
  975. X                set_font();
  976. X                break;
  977. X            default:
  978. X                ignore("<ESC> h n");
  979. X                break;
  980. X        }
  981. X        break;
  982. X    case S_DOUBLEHEIGHT:
  983. X        debug_state("S_DOUBLEHEIGHT",c);
  984. X        state = S_BASE;
  985. X        if (c == '\0' || c == '0')    doubleheight = 0;
  986. X        else if (c == '\1' || c == '1')    doubleheight = 1;
  987. X        set_font();
  988. X        break;
  989. X    case S_SETTAB:
  990. X        debug_state("S_SETTAB",c);
  991. X        if (c == 0) {
  992. X            state = S_BASE;
  993. X            for (; tabindex <= NUM_TABS; tabindex++)
  994. X                tabs[tabindex] = -1;
  995. X        }
  996. X        else {
  997. X            if ( tabindex < NUM_TABS )
  998. X                tabs[tabindex++] = c;
  999. X        }
  1000. X        break;
  1001. X    case S_VSETTABCHANNEL:
  1002. X        debug_state("S_VSETTABCHANNEL",c);
  1003. X        state = S_SETVTAB1;
  1004. X        if (c > 7) {
  1005. X            invalid("<ESC> b n");
  1006. X            vsettabchannel = 0;
  1007. X        }
  1008. X        else
  1009. X            vsettabchannel = c;
  1010. X        break;
  1011. X    case S_SETVTAB1:
  1012. X        debug_state("S_SETVTAB1",c);
  1013. X        if (c == 0) { /* no vtabs */
  1014. X            state = S_BASE;
  1015. X            vtabs[vsettabchannel][tabindex] = 0;
  1016. X        }
  1017. X        else {
  1018. X            state = S_SETVTAB2;
  1019. X            vtabs[vsettabchannel][tabindex++] = c;
  1020. X        }
  1021. X        break;
  1022. X    case S_SETVTAB2:
  1023. X        debug_state("S_SETVTAB2",c);
  1024. X        if (c == 0) {
  1025. X            state = S_BASE;
  1026. X            for (; tabindex <= NUM_VTABS; tabindex++)
  1027. X                vtabs[vsettabchannel][tabindex] = -1;
  1028. X        }
  1029. X        else {
  1030. X            if ( tabindex < NUM_VTABS )
  1031. X                vtabs[vsettabchannel][tabindex++] = c;
  1032. X        }
  1033. X        break;
  1034. X    case S_VTABCHANNEL:
  1035. X        debug_state("S_VTABCHANNEL",c);
  1036. X        state = S_BASE;
  1037. X        if (c > 7)
  1038. X            invalid("<ESC> / n");
  1039. X        else
  1040. X            vtabchannel = c;
  1041. X        break;
  1042. X    case S_TABINC:
  1043. X        debug_state("S_TABINC",c);
  1044. X        if (c == '\0' || c == '0')
  1045. X            state = S_HTABINC;
  1046. X        else if (c == '\1' || c == '1')    
  1047. X            state = S_VTABINC;
  1048. X        else {
  1049. X            state = S_IGNORE1;
  1050. X            invalid("<ESC> e n");
  1051. X        }
  1052. X    case S_HTABINC:
  1053. X        debug_state("S_HTABINC",c);
  1054. X        state = S_BASE;
  1055. X        {
  1056. X        int i;
  1057. X        for (i=0; i<NUM_TABS; i++)
  1058. X            tabs[i] = (i+1) * c;
  1059. X        tabs[NUM_TABS] = -1;
  1060. X        }
  1061. X        break;
  1062. X    case S_VTABINC:
  1063. X        debug_state("S_VTABINC",c);
  1064. X        state = S_BASE;
  1065. X        {
  1066. X        int i;
  1067. X        for (i=0; i<NUM_VTABS; i++)
  1068. X            vtabs[vtabchannel][i] = (i+1) * c;
  1069. X        vtabs[vtabchannel][NUM_VTABS] = -1;
  1070. X        }
  1071. X        break;
  1072. X    case S_SKIP:
  1073. X        debug_state("S_SKIP",c);
  1074. X        if (c == '\0' || c == '0')
  1075. X            state = S_HSKIP;
  1076. X        else if (c == '\1' || c == '1')    
  1077. X            state = S_VSKIP;
  1078. X        else {
  1079. X            state = S_IGNORE1;
  1080. X            invalid("<ESC> f n");
  1081. X        }
  1082. X    case S_HSKIP:
  1083. X        debug_state("S_HSKIP",c);
  1084. X        state = S_BASE;
  1085. X        {
  1086. X        int i;
  1087. X        for (i=0; i<c; i++)
  1088. X            dochar(' ');
  1089. X        }
  1090. X        break;
  1091. X    case S_VSKIP:
  1092. X        debug_state("S_VSKIP",c);
  1093. X        state = S_BASE;
  1094. X        {
  1095. X        int i;
  1096. X        for (i=0; i<c; i++)
  1097. X            newline();
  1098. X        }
  1099. X        break;
  1100. X    case S_PAGELENGTH:
  1101. X        debug_state("S_PAGELENGTH",c);
  1102. X        if (c !=0) {
  1103. X            state = S_BASE;
  1104. X            ystop = c * line_space;
  1105. X            page_ystop = ystop;
  1106. X        }
  1107. X        else {
  1108. X            state = S_PAGEINCH;
  1109. X        }
  1110. X        break;
  1111. X    case S_PAGEINCH:
  1112. X        debug_state("S_PAGEINCH",c);
  1113. X        state = S_BASE;
  1114. X        ystop = c * get_pointy(1);
  1115. X        page_ystop = ystop;
  1116. X        break;
  1117. X    case S_BOTTOM:
  1118. X        debug_state("S_BOTTOM",c);
  1119. X        state = S_BASE;
  1120. X        {
  1121. X            int temp;
  1122. X            temp = page_ystop - c * line_space;
  1123. X            if (ystart + line_space < temp)
  1124. X                ystop = temp;
  1125. X            else
  1126. X                invalid("<ESC> N n");
  1127. X        }
  1128. X        break;
  1129. X    case S_TOP:
  1130. X        debug_state("S_TOP",c);
  1131. X        state = S_BASE;
  1132. X        ystart = c * line_space + YSTART ;
  1133. X        {
  1134. X            int temp;
  1135. X            temp = (c-1) * line_space + YSTART ;
  1136. X            if (temp + line_space < ystop)
  1137. X                ystart = temp;
  1138. X            else
  1139. X                invalid("<ESC> r n or <ESC> c n");
  1140. X        }
  1141. X        break;
  1142. X    case S_RIGHT:
  1143. X        debug_state("S_RIGHT",c);
  1144. X        state = S_BASE;
  1145. X        {
  1146. X            int temp;
  1147. X            temp =  c * point_sizex;
  1148. X            if (xstart + point_sizex < temp)
  1149. X                xstop = temp;
  1150. X            else
  1151. X                invalid("<ESC> Q n");
  1152. X        }
  1153. X        break;
  1154. X    case S_LEFT:
  1155. X        debug_state("S_LEFT",c);
  1156. X        state = S_BASE;
  1157. X        {
  1158. X            int temp;
  1159. X            temp = c * point_sizex;
  1160. X            if (temp + point_sizex < xstop)
  1161. X                xstart = temp;
  1162. X            else
  1163. X                invalid("<ESC> l n");
  1164. X        }
  1165. X        cx = xstart;
  1166. X        break;
  1167. X    case S_ABSOLUTE1:
  1168. X        debug_state("S_ABSOLUTE1",c);
  1169. X        state = S_ABSOLUTE2;
  1170. X        dotposition = c;
  1171. X        break;
  1172. X    case S_ABSOLUTE2:
  1173. X        debug_state("S_ABSOLUTE2",c);
  1174. X        state = S_BASE;
  1175. X        dotposition = (c*256 + dotposition) * get_pointx(60);
  1176. X        if (dotposition < xstop)
  1177. X            cx = dotposition;
  1178. X        break;
  1179. X    case S_RELATIVE1:
  1180. X        debug_state("S_RELATIVE1",c);
  1181. X        state = S_RELATIVE2;
  1182. X        dotposition = c;
  1183. X        break;
  1184. X    case S_RELATIVE2:
  1185. X        debug_state("S_RELATIVE2",c);
  1186. X        state = S_BASE;
  1187. X        dotposition = c*256 + dotposition;
  1188. X        if ((unsigned int)dotposition > (unsigned int)32767) {
  1189. X            dotposition = (int)(dotposition - 65536L);
  1190. X        }
  1191. X        if (lq_mode) {
  1192. X            if (nlq_mode)
  1193. X                dotposition = dotposition * get_pointx(180);
  1194. X            else
  1195. X                dotposition = dotposition * get_pointx(120);
  1196. X            if (cx + dotposition < xstop)
  1197. X                cx += dotposition;
  1198. X        }
  1199. X        else
  1200. X            invalid("<ESC> \\");
  1201. X        break;
  1202. X    case S_MACRO:
  1203. X        debug_state("S_MACRO",c);
  1204. X        if (c == 1) {
  1205. X            state = S_BASE;
  1206. X            for (mindex=0; macro[mindex]!=30; mindex++)
  1207. X                dochar((unsigned char)macro[mindex]);
  1208. X            break;
  1209. X        }
  1210. X        else {
  1211. X            state = S_SETMACRO;
  1212. X            mindex = 0;
  1213. X        }
  1214. X        /* no break */
  1215. X    case S_SETMACRO:
  1216. X        debug_state("S_SETMACRO",c);
  1217. X        if (mindex<MACROMAX)
  1218. X            macro[mindex++] = c;
  1219. X        if (c == 30) {
  1220. X            macro[mindex] = c;
  1221. X            state = S_BASE;
  1222. X        }
  1223. X        break;
  1224. X    case S_IBM_MODE:
  1225. X        debug_state("S_IBM_MODE",c);
  1226. X        state = S_BASE;
  1227. X        if (c == '\0' || c == '0')    ibm_graphic = 0;
  1228. X        else if (c == '\1' || c == '1')    ibm_graphic = 1;
  1229. X        else invalid("<ESC> t n");
  1230. X        break;
  1231. X    case S_INTERNATIONAL:
  1232. X        debug_state("S_INTERNATIONAL",c);
  1233. X        state = S_BASE;
  1234. X        if (c > MAX_COUNTRY)
  1235. X            invalid("<ESC> R n");
  1236. X        else {
  1237. X            country_num = c;
  1238. X            fprintf(outfile,"%s InternationalSet\n",international[country_num]);
  1239. X        }
  1240. X        break;
  1241. X    case S_LITERAL:
  1242. X        debug_state("S_LITERAL",c);
  1243. X        state = S_BASE;
  1244. X        pchar(c);
  1245. X        break;
  1246. X    case S_LITERAL1:
  1247. X        debug_state("S_LITERAL1",c);
  1248. X        state = S_LITERAL2;
  1249. X        lcount = c;
  1250. X        break;
  1251. X    case S_LITERAL2:
  1252. X        debug_state("S_LITERAL2",c);
  1253. X        state = S_LITERAL_COUNT;
  1254. X        lcount = 256 * c + lcount;
  1255. X        if (lcount == 0)
  1256. X            state = S_BASE;
  1257. X        break;
  1258. X    case S_LITERAL_COUNT:
  1259. X        debug_state("S_LITERAL_COUNT",c);
  1260. X        pchar(c);
  1261. X        lcount--;
  1262. X        if (lcount == 0) {
  1263. X            state = S_BASE;
  1264. X        }
  1265. X        break;
  1266. X    case S_SCREENDUMP:
  1267. X        debug_state("S_SCREENDUMP",c);
  1268. X            /* recognise only \r and \n */
  1269. X            switch(c) {
  1270. X        case '\n':
  1271. X            putline();
  1272. X            newline();
  1273. X            if (auto_cr)
  1274. X                cx = xstart;
  1275. X            break;
  1276. X        case '\r':
  1277. X            putline();
  1278. X            cx = xstart;
  1279. X            if (auto_lf)
  1280. X                newline();
  1281. X            break;
  1282. X        default:
  1283. X            pchar(c);
  1284. X            break;
  1285. X        }
  1286. X        break;
  1287. X    case S_GRAPHIC_MODE:
  1288. X        debug_state("S_GRAPHIC_MODE",c);
  1289. X        state = S_GRAPHIC1;
  1290. X        if ( (c <= 6) || (c>=32 && c<=40) )
  1291. X            g_mode = c;
  1292. X        else
  1293. X            invalid("<ESC> *");
  1294. X        break;
  1295. X    case S_GRAPHIC1:
  1296. X        debug_state("S_GRAPHIC1",c);
  1297. X        state = S_GRAPHIC2;
  1298. X        gcount = c;
  1299. X        if (g_mode >= 32) {
  1300. X            g_dpi = g_dpi_table[g_mode-32];
  1301. X            state = S_GRAPHIC24_2;
  1302. X        }
  1303. X        else {
  1304. X            g_dpi = g_dpi_table[g_mode];
  1305. X        }
  1306. X        break;
  1307. X    case S_GRAPHIC2:
  1308. X        debug_state("S_GRAPHIC2",c);
  1309. X        state = S_GRAPHIC;
  1310. X        gcount = 256 * c + gcount ;
  1311. X        if (gcount == 0) {
  1312. X            state = S_BASE;
  1313. X            break;
  1314. X        }
  1315. X        gwidth = (int)( (long)get_pointx(1)*gcount/g_dpi);
  1316. X        if (lq_mode) {
  1317. X            fprintf(outfile,"gsave\n%d %d translate\n",cx,cy+6*get_pointy(180));
  1318. X            fprintf(outfile,"%d %d scale\n", get_pointy(180)*24, gwidth);
  1319. X        }
  1320. X        else {
  1321. X            fprintf(outfile,"gsave\n%d %d translate\n",cx,cy+get_pointy(72));
  1322. X            fprintf(outfile,"%d %d scale\n", get_pointy(72)*8, gwidth);
  1323. X        }
  1324. X        fprintf(outfile,"8 %d true [0 8 %d 0 0 8]", gcount, gcount);
  1325. X        fprintf(outfile," {currentfile graphicbuf readhexstring pop} \nimagemask\n");
  1326. X        cx += gwidth;
  1327. X        break;
  1328. X    case S_GRAPHIC:
  1329. X        debug_state("S_GRAPHIC",c);
  1330. X        hexout(c);
  1331. X        gcount--;
  1332. X        if ( (gcount & 0x1f) == 0 )
  1333. X            (void)fputc('\n',outfile);
  1334. X        if (gcount == 0) {
  1335. X            fputs("grestore\n",outfile);
  1336. X            state = S_BASE;
  1337. X        }
  1338. X        break;
  1339. X    case S_DEF_GRAPHIC:
  1340. X        debug_state("S_DEF_GRAPHIC",c);
  1341. X        switch(c)
  1342. X        {
  1343. X        case 'K':
  1344. X            state = S_DEF_K;
  1345. X            break;
  1346. X        case 'L':
  1347. X            state = S_DEF_L;
  1348. X            break;
  1349. X        case 'Y':
  1350. X            state = S_DEF_Y;
  1351. X            break;
  1352. X        case 'Z':
  1353. X            state = S_DEF_Z;
  1354. X            break;
  1355. X        default:
  1356. X            state = S_IGNORE1;
  1357. X            invalid("ESC ? n0 n1");
  1358. X            break;
  1359. X        }
  1360. X        break;
  1361. X    case S_DEF_K:
  1362. X        debug_state("S_DEF_K",c);
  1363. X        state = S_BASE;
  1364. X        if ( (c <= 6) || (c>=32 && c<=40) )
  1365. X            g_mode_k = c;
  1366. X        else
  1367. X            invalid("<ESC> ? K n");
  1368. X        break;
  1369. X    case S_DEF_L:
  1370. X        debug_state("S_DEF_L",c);
  1371. X        state = S_BASE;
  1372. X        if ( (c <= 6) || (c>=32 && c<=40) )
  1373. X            g_mode_l = c;
  1374. X        else
  1375. X            invalid("<ESC> ? L n");
  1376. X        break;
  1377. X    case S_DEF_Y:
  1378. X        debug_state("S_DEF_Y",c);
  1379. X        state = S_BASE;
  1380. X        if ( (c <= 6) || (c>=32 && c<=40) )
  1381. X            g_mode_y = c;
  1382. X        else
  1383. X            invalid("<ESC> ? Y n");
  1384. X        break;
  1385. X    case S_DEF_Z:
  1386. X        debug_state("S_DEF_Z",c);
  1387. X        state = S_BASE;
  1388. X        if ( (c<= 6) || (c>=32 && c<=40) )
  1389. X            g_mode_z = c;
  1390. X        else
  1391. X            invalid("<ESC> ? Z n");
  1392. X        break;
  1393. X    case S_GRAPHIC9_MODE:
  1394. X        debug_state("S_GRAPHIC9_MODE",c);
  1395. X        state = S_GRAPHIC9_1;
  1396. X        if (c > 6) {
  1397. X            invalid("<ESC> ^");
  1398. X            g_dpi = g_dpi_table[0];
  1399. X        }
  1400. X        else {
  1401. X            g_dpi = g_dpi_table[c];
  1402. X            g_mode = c;
  1403. X        }
  1404. X        break;
  1405. X    case S_GRAPHIC9_1:
  1406. X        debug_state("S_GRAPHIC9_1",c);
  1407. X        state = S_GRAPHIC9_2;
  1408. X        gcount = c;
  1409. X        break;
  1410. X    case S_GRAPHIC9_2:
  1411. X        debug_state("S_GRAPHIC9_2",c);
  1412. X        state = S_GRAPHIC9_TOP;
  1413. X        gcount = 256 * c + gcount ;
  1414. X        if (gcount == 0) {
  1415. X            state = S_BASE;
  1416. X            break;
  1417. X        }
  1418. X        gwidth = (int)( (long)get_pointx(1)*gcount/g_dpi);
  1419. X        if (lq_mode) {
  1420. X            invalid("<ESC> ^");
  1421. X            fprintf(outfile,"gsave\n%d %d translate\n",cx,cy+9*get_pointy(60));
  1422. X            fprintf(outfile,"%d %d scale\n", get_pointy(60)*16, gwidth);
  1423. X        }
  1424. X        else {
  1425. X            fprintf(outfile,"gsave\n%d %d translate\n",cx,cy+9*get_pointy(72));
  1426. X            fprintf(outfile,"%d %d scale\n", get_pointy(72)*16, gwidth);
  1427. X        }
  1428. X        fprintf(outfile,"16 %d true [0 16 %d 0 0 16]", gcount, gcount);
  1429. X        fprintf(outfile," {currentfile graphicbuf readhexstring pop} \nimagemask\n");
  1430. X        cx += gwidth;
  1431. X        break;
  1432. X    case S_GRAPHIC9_TOP:
  1433. X        debug_state("S_GRAPHIC9_TOP",c);
  1434. X        state = S_GRAPHIC9_BOTTOM;
  1435. X        hexout(c);
  1436. X        break;
  1437. X    case S_GRAPHIC9_BOTTOM:
  1438. X        debug_state("S_GRAPHIC9_BOTTOM",c);
  1439. X        state = S_GRAPHIC9_TOP;
  1440. X        c &= 0x80;
  1441. X        hexout(c);
  1442. X        gcount--;
  1443. X        if ( (gcount & 0x0f) == 0 )
  1444. X            (void)fputc('\n',outfile);
  1445. X        if (gcount == 0) {
  1446. X            fputs("grestore\n",outfile);
  1447. X            state = S_BASE;
  1448. X        }
  1449. X        break;
  1450. X    case S_GRAPHIC24_2:
  1451. X        debug_state("S_GRAPHIC24_2",c);
  1452. X        state = S_GRAPHIC24_TOP;
  1453. X        gcount = 256 * c + gcount ;
  1454. X        if (gcount == 0) {
  1455. X            state = S_BASE;
  1456. X            break;
  1457. X        }
  1458. X        gwidth = (int)( (long)get_pointx(1)*gcount/g_dpi);
  1459. X        if (lq_mode) {
  1460. X            fprintf(outfile,"gsave\n%d %d translate\n",cx,cy+6*get_pointy(180));
  1461. X            fprintf(outfile,"%d %d scale\n", get_pointy(180)*24, gwidth);
  1462. X        }
  1463. X        else {
  1464. X            fprintf(outfile,"gsave\n%d %d translate\n",cx,cy+get_pointy(72));
  1465. X            fprintf(outfile,"%d %d scale\n", get_pointy(72)*8, gwidth);
  1466. X        }
  1467. X        fprintf(outfile,"24 %d true [0 24 %d 0 0 24]", gcount, gcount);
  1468. X        fprintf(outfile," {currentfile graphicbuf readhexstring pop} \nimagemask\n");
  1469. X        cx += gwidth;
  1470. X        break;
  1471. X    case S_GRAPHIC24_TOP:
  1472. X        debug_state("S_GRAPHIC24_TOP",c);
  1473. X        state = S_GRAPHIC24_MIDDLE;
  1474. X        hexout(c);
  1475. X        break;
  1476. X    case S_GRAPHIC24_MIDDLE:
  1477. X        debug_state("S_GRAPHIC24_MIDDLE",c);
  1478. X        state = S_GRAPHIC24_BOTTOM;
  1479. X        hexout(c);
  1480. X        break;
  1481. X    case S_GRAPHIC24_BOTTOM:
  1482. X        debug_state("S_GRAPHIC24_BOTTOM",c);
  1483. X        state = S_GRAPHIC24_TOP;
  1484. X        hexout(c);
  1485. X        gcount--;
  1486. X        if ( (gcount & 0x07) == 0 )
  1487. X            (void)fputc('\n',outfile);
  1488. X        if (gcount == 0) {
  1489. X            fputs("grestore\n",outfile);
  1490. X            state = S_BASE;
  1491. X        }
  1492. X        break;
  1493. X    case S_ESC:
  1494. X        debug_state("S_ESC",c);
  1495. X        state = S_BASE;
  1496. X        switch (c)
  1497. X        {
  1498. X        case '\n':    /* reverse line feed - Star NL-10 */
  1499. X            cy -= line_space;
  1500. X            break;
  1501. X        case '\f':    /* reverse form feed - Star NL-10 */
  1502. X            cy = ystart;
  1503. X            break;
  1504. X        case 14:    /* 0x0e - select one line expanded */
  1505. X            oneline_doublewidth = 1;
  1506. X            set_font();
  1507. X            break;
  1508. X        case 15:    /* select condensed */
  1509. X            condensed = 1;
  1510. X            set_font();
  1511. X            break;
  1512. X        case 25:    /* paper controls */
  1513. X            ignore("<ESC> <EM> n");
  1514. X            state = S_IGNORE1;
  1515. X            break;
  1516. X        case '!':    /* master print mode */
  1517. X            state = S_MASTER;
  1518. X            break;
  1519. X        case '#':    /* accept eight bit */
  1520. X            eight_bit = 0;
  1521. X            break;
  1522. X        case '$':    /* absolute dot position - LQ-800 */
  1523. X            state = S_ABSOLUTE1;
  1524. X            break;
  1525. X        case '%':    /* select download character set */
  1526. X            ignore("<ESC> % n");
  1527. X            state = S_IGNORE1;
  1528. X            break;
  1529. X        case '*':    /* select graphic mode */
  1530. X            state = S_GRAPHIC_MODE;
  1531. X            break;
  1532. X        case '+':    /* macro - Star NL-10 */
  1533. X            state = S_MACRO;
  1534. X            break;
  1535. X        case '-':
  1536. X            state = S_UNDERLINE;
  1537. X            break;
  1538. X        case '/':    /* select vertical tab channel */
  1539. X            state = S_VTABCHANNEL;
  1540. X            break;
  1541. X        case '0':    /* set line spacing to 1/8 inch */
  1542. X            line_space = get_pointy(8);
  1543. X            break;
  1544. X        case '1':    /* set line spacing to 7/72 inch */
  1545. X            line_space = 7 * get_pointy(72);
  1546. X            break;
  1547. X        case '2':    /* set line spacing to 1/6 inch */
  1548. X            line_space = get_pointy(6);
  1549. X            break;
  1550. X        case '3':    /* set line spacing to n/216 or n/180 inch */
  1551. X            state = S_FINE_LINESPACE;
  1552. X            break;
  1553. X        case '4':
  1554. X            italic = 1;
  1555. X            set_font();
  1556. X            break;
  1557. X        case '5':
  1558. X            italic = 0;
  1559. X            set_font();
  1560. X            break;
  1561. X        case '6':    /* expand printable area */
  1562. X            expand_print = 1;
  1563. X            break;
  1564. X        case '7':    /* cancels expand printable area */
  1565. X            expand_print = 0;
  1566. X            break;
  1567. X        case '8':    /* disable paper-out detector */
  1568. X            ignore("<ESC> 8");
  1569. X            break;
  1570. X        case '9':    /* enable paper-out detector */
  1571. X            ignore("<ESC> 9");
  1572. X            break;
  1573. X        case ':':    /* copy ROM characters to user defined */
  1574. X            state = S_IGNORE3;
  1575. X            ignore("<ESC> :");
  1576. X            break;
  1577. X        case '<':
  1578. X            if (lq_mode)
  1579. X                cx = 0; /* print head to home */
  1580. X            else
  1581. X                /* select one line uni-directional printing */
  1582. X                ignore("<ESC> <");
  1583. X            break;
  1584. X        case '=':    /* set eighth bit to 0 */
  1585. X            eight_bit = -1;
  1586. X            break;
  1587. X        case '>':    /* set eighth bit to 1 */
  1588. X            eight_bit = 1;
  1589. X            break;
  1590. X        case '?':
  1591. X            state = S_DEF_GRAPHIC;
  1592. X            break;
  1593. X        case '@':
  1594. X            reset_printer();
  1595. X            break;
  1596. X        case 'A':
  1597. X            state = S_LINESPACE;
  1598. X            break;
  1599. X        case 'B':
  1600. X            state = S_SETVTAB1;
  1601. X            vsettabchannel = 0;
  1602. X            tabindex = 0;
  1603. X            break;
  1604. X        case 'C':
  1605. X            state = S_PAGELENGTH;
  1606. X            break;
  1607. X        case 'D':
  1608. X            state = S_SETTAB;
  1609. X            tabindex = 0;
  1610. X            break;
  1611. X        case 'E':
  1612. X            emphasize = 1;
  1613. X            set_font();
  1614. X            break;
  1615. X        case 'F':
  1616. X            emphasize = 0;
  1617. X            set_font();
  1618. X            break;
  1619. X        case 'G':
  1620. X            highlight = 1;
  1621. X            set_font();
  1622. X            break;
  1623. X        case 'H':
  1624. X            highlight = 0;
  1625. X            set_font();
  1626. X            break;
  1627. X        case 'I':  /* allow use of characters 0x80-0x9f - Star NL-10 */
  1628. X            state = S_IGNORE1;
  1629. X            ignore("<ESC> I n");
  1630. X            break;
  1631. X        case 'J':
  1632. X            state = S_LINEFEED;
  1633. X            break;
  1634. X        case 'K':
  1635. X            state = S_GRAPHIC1;
  1636. X            g_mode = g_mode_k;
  1637. X            break;
  1638. X        case 'L':
  1639. X            state = S_GRAPHIC1;
  1640. X            g_mode = g_mode_l;
  1641. X            break;
  1642. X        case 'M':
  1643. X            elite = 1;
  1644. X            fifteen = 0;
  1645. X            set_font();
  1646. X            break;
  1647. X        case 'N':
  1648. X            state = S_BOTTOM;
  1649. X            break;
  1650. X        case 'O':
  1651. X            ystart = YSTART;
  1652. X            ystop = page_ystop;
  1653. X            break;
  1654. X        case 'P':
  1655. X            elite = 0;
  1656. X            fifteen = 0;
  1657. X            set_font();
  1658. X            break;
  1659. X        case 'Q':
  1660. X            state = S_RIGHT;
  1661. X            break;
  1662. X        case 'R':    /* international character set */
  1663. X            state = S_INTERNATIONAL;
  1664. X            break;
  1665. X        case 'S':
  1666. X            state = S_SUBSCRIPT;
  1667. X            break;
  1668. X        case 'T':
  1669. X            subscript = 0;
  1670. X            break;
  1671. X        case 'U':    /* unidirectional printint */
  1672. X            state = S_IGNORE1;
  1673. X            ignore("<ESC> U n");
  1674. X            break;
  1675. X        case 'W':
  1676. X            state = S_DOUBLE;
  1677. X            break;
  1678. X        case 'Y':
  1679. X            state = S_GRAPHIC1;
  1680. X            g_mode = g_mode_y;
  1681. X            break;
  1682. X        case 'Z':
  1683. X            state = S_GRAPHIC1;
  1684. X            g_mode = g_mode_z;
  1685. X            break;
  1686. X        case '\\':
  1687. X            if (lq_mode) 
  1688. X                /* relative dot position - LQ-800 */
  1689. X                state = S_RELATIVE1;
  1690. X            else
  1691. X                if (ibm_graphic)
  1692. X                    state = S_LITERAL1;
  1693. X                else
  1694. X                    state = S_RELATIVE1;
  1695. X            break;
  1696. X        case '^':
  1697. X            if (ibm_graphic)
  1698. X                state = S_LITERAL;    /* literal character */
  1699. X            else
  1700. X                state = S_GRAPHIC9_MODE; /* 9 pin graphics */
  1701. X            break;
  1702. X        case 'a':    /* justification */
  1703. X            state = S_IGNORE1;
  1704. X            ignore("<ESC> a n");
  1705. X            break;
  1706. X        case 'b':
  1707. X            state = S_VSETTABCHANNEL;
  1708. X            tabindex = 0;
  1709. X            break;
  1710. X        case 'c':    /* top margin - Star NX-1000 */
  1711. X            state = S_TOP;
  1712. X            break;
  1713. X        case 'e':
  1714. X            state = S_TABINC;
  1715. X            break;
  1716. X        case 'f':
  1717. X            state = S_SKIP;
  1718. X            break;
  1719. X        case 'g':    /* 15-pitch characters - LQ-800 */
  1720. X            elite = 0;
  1721. X            fifteen = 1;
  1722. X            set_font();
  1723. X            break;
  1724. X        case 'h':    /* enlarge characters - Star NL-10 */
  1725. X            state = S_ENLARGE;
  1726. X            break;
  1727. X        case 'i':    /* immediate print mode - Star NL-10 */
  1728. X            state = S_IGNORE1;
  1729. X            ignore("<ESC> i n");
  1730. X            break;
  1731. X        case 'j':    /* reverse line feed - Star NL-10 */
  1732. X            state = S_REV_LINEFEED;
  1733. X            break;
  1734. X        case 'k':    /* select font family */
  1735. X            state = S_IGNORE1;
  1736. X            ignore("<ESC> k n");
  1737. X            break;
  1738. X        case 'l':
  1739. X            state = S_LEFT;
  1740. X            break;
  1741. X        case 'm':    /* select special graphics */
  1742. X            state = S_IGNORE1;
  1743. X            ignore("<ESC> m n");
  1744. X            break;
  1745. X        case 'p':    /* proportional print - Star NL-10 */
  1746. X            state = S_IGNORE1;
  1747. X            ignore("<ESC> p n");
  1748. X            break;
  1749. X        case 'r':    /* top margin - Star NL-10 */
  1750. X            state = S_TOP;
  1751. X            break;
  1752. X        case 's':    /* half speed */
  1753. X            state = S_IGNORE1;
  1754. X            ignore("<ESC> s n");
  1755. X            break;
  1756. X        case 't':    /* italic / graphics & international */
  1757. X            state = S_IBM_MODE;
  1758. X            break;
  1759. X        case 'w':    /* double height characters - Star NX-1000 */
  1760. X            state = S_DOUBLEHEIGHT;
  1761. X            break;
  1762. X        case 'x':    /* NLQ mode */
  1763. X            state = S_NLQMODE;
  1764. X            break;
  1765. X        case '~':    /* slash zero - Star NL-10 */
  1766. X            state = S_IGNORE1;
  1767. X            ignore("<ESC> ~ n");
  1768. X            break;
  1769. X        default:
  1770. X            if (debug)
  1771. X                fprintf(stderr,"Unknown sequence: <ESC> 0x%x\n",c);
  1772. X            break;
  1773. X        }
  1774. X        break;
  1775. X       case S_BASE:
  1776. X        if (debug>=3)
  1777. X            debug_state("S_BASE",c);
  1778. X        if (!expand_print && c>=0x80 && c<=0x9f)
  1779. X            c &= 0x7f;
  1780. X        switch(c)
  1781. X        {
  1782. X        case 7:        /* bell (on stderr) */
  1783. X            if (debug)
  1784. X                (void)fputc((char)c,stderr);
  1785. X            break;
  1786. X        case '\b':    /* back space */
  1787. X            putline();
  1788. X            cx -= point_sizex;
  1789. X            break;
  1790. X        case '\t':
  1791. X            {
  1792. X                int i,l;
  1793. X
  1794. X                l = cx / point_sizex + ptr;
  1795. X                for (i = 0; i < NUM_TABS && tabs[i] <= l; i++)
  1796. X                    ;
  1797. X                if (tabs[i] == -1) break;
  1798. X                i = tabs[i] - l;
  1799. X                while (i-- > 0) dochar(' ')
  1800. X                    ;
  1801. X            }
  1802. X            break;
  1803. X        case '\n': 
  1804. X            putline();
  1805. X            newline();
  1806. X            if (auto_cr) {
  1807. X                cx = xstart;
  1808. X                if (oneline_doublewidth) {
  1809. X                    oneline_doublewidth = 0;
  1810. X                    set_font();
  1811. X                }
  1812. X            }
  1813. X            break;
  1814. X        case 11:    /* vertical tab */
  1815. X            putline();
  1816. X            if (vtabs[vtabchannel][0] == 0)
  1817. X                newline();
  1818. X            else {
  1819. X                int i,l;
  1820. X                l = cy / line_space;
  1821. X                for (i = 0; i < NUM_VTABS &&
  1822. X                    vtabs[vtabchannel][i] <= l; i++) ;
  1823. X                if (vtabs[vtabchannel][i] == -1) {
  1824. X                    eject_page();
  1825. X                }
  1826. X                else {
  1827. X                    cy = vtabs[vtabchannel][i] * line_space
  1828. X                        + YSTART;
  1829. X                }
  1830. X            }
  1831. X            break;
  1832. X        case '\f':
  1833. X            putline();
  1834. X            eject_page();
  1835. X            break;
  1836. X        case '\r':
  1837. X            putline();
  1838. X            cx = xstart;
  1839. X            if (oneline_doublewidth) {
  1840. X                oneline_doublewidth = 0;
  1841. X                set_font();
  1842. X            }
  1843. X            if (auto_lf)
  1844. X                newline();
  1845. X            break;
  1846. X        case 14:    /* 0x0e - select one line expanded */
  1847. X            putline();
  1848. X            oneline_doublewidth = 1;
  1849. X            set_font();
  1850. X            break;
  1851. X        case 15:    /* 0x0f - select condensed */
  1852. X            putline();
  1853. X            condensed = 1;
  1854. X            set_font();
  1855. X            break;
  1856. X        case 17:    /* 0x11 - set printer off line */
  1857. X            ignore("<DC1>");
  1858. X            break;
  1859. X        case 18:    /* 0x12 - cancel condensed */
  1860. X            putline();
  1861. X            condensed = 0;
  1862. X            set_font();
  1863. X            break;
  1864. X        case 19:    /* 0x11 - set printer on line */
  1865. X            ignore("<DC3>");
  1866. X            break;
  1867. X        case 20:    /* 0x14 - cancel one line expanded */
  1868. X            putline();
  1869. X            oneline_doublewidth = 0;
  1870. X            set_font();
  1871. X            break;
  1872. X        case 24:    /* 0x18 - cancel line */
  1873. X            ignore("<CAN>");
  1874. X            break;
  1875. X        case 26:    /* CTRL-Z */
  1876. X            break;
  1877. X        case '\033':
  1878. X            putline();
  1879. X            state = S_ESC;
  1880. X            break;
  1881. X        case 127:    /* 0x7f - delete char */
  1882. X            ignore("<DEL>");
  1883. X            break;
  1884. X        default:    /* print character */
  1885. X            pchar(c);
  1886. X            break;
  1887. X        }
  1888. X        break;
  1889. X    }
  1890. X}
  1891. X
  1892. Xvoid
  1893. Xinit_printer(void)
  1894. X{
  1895. Xunsigned int nbytes;
  1896. X
  1897. X    maxx = page_formats[paper_type].nchars * get_pointx(PICA);
  1898. X    maxy = page_formats[paper_type].nlines * get_pointy(FONTHEIGHT);
  1899. X    line_space = get_pointy(FONTHEIGHT);
  1900. X
  1901. X    if (left > page_formats[paper_type].nchars) {
  1902. X        fprintf(stderr,"Left margin greater than right margin\n");
  1903. X        exit(1);
  1904. X    }
  1905. X    xstart = left * get_pointx(PICA);
  1906. X    xstop = maxx;
  1907. X    ystart = YSTART;
  1908. X    ystop = maxy;
  1909. X    page_ystop = ystop;
  1910. X
  1911. X    fputs("%!PS-Adobe-2.0\n",outfile);
  1912. X    fprintf(outfile,"%%%%BoundingBox: 0 0 %d %d\n",
  1913. X        page_formats[paper_type].urx, page_formats[paper_type].ury);
  1914. X    fputs("%%Creator: epsonps.c\n",outfile);
  1915. X    fputs("%%Pages: (atend)\n",outfile);
  1916. X    fputs("%%EndComments\n",outfile);
  1917. X    fputs("/saveobj1 save def\n",outfile);
  1918. X    if (page_formats[paper_type].rotate) {
  1919. X        fputs("90 rotate\n",outfile);
  1920. X        fprintf(outfile,"%d %d translate\n",page_formats[paper_type].lly,
  1921. X          -page_formats[paper_type].llx);
  1922. X        fprintf(outfile,"%d %d div %d %d div scale\n",
  1923. X          page_formats[paper_type].ury-page_formats[paper_type].lly, maxx,
  1924. X          page_formats[paper_type].llx-page_formats[paper_type].urx, maxy);
  1925. X    }
  1926. X    else {
  1927. X        fprintf(outfile,"%d %d translate\n",page_formats[paper_type].llx,
  1928. X          page_formats[paper_type].ury);
  1929. X        fprintf(outfile,"%d %d div %d %d div scale\n",
  1930. X          page_formats[paper_type].urx-page_formats[paper_type].llx, maxx,
  1931. X          page_formats[paper_type].lly-page_formats[paper_type].ury, maxy);
  1932. X    }
  1933. X
  1934. X    fprintf(outfile,"/xdpi %d def\n", get_pointx(1));
  1935. X    fprintf(outfile,"/ydpi %d def\n", get_pointy(1));
  1936. X    fputs("1.5 setlinewidth\nnewpath\n",outfile);
  1937. X
  1938. X    /* send the header file */
  1939. X    fputs("%%BeginProcSet: epsonps.pro\n",outfile);
  1940. X    while (!feof(prologfile)) {
  1941. X        nbytes = fread(buffer, sizeof(char), EPSONBUFSIZE,
  1942. X            prologfile);
  1943. X        (void)fwrite(buffer, sizeof(char), nbytes, outfile);
  1944. X    }
  1945. X    fputs("%%EndProcSet\n",outfile);
  1946. X
  1947. X    fprintf(outfile,"%s InternationalSet\n",international[country_num]);
  1948. X
  1949. X    fputs("%%%%EndProlog\n",outfile);
  1950. X
  1951. X        if (screendump_mode) state = S_SCREENDUMP;
  1952. X    init_tabs();    /* initialise tabs */
  1953. X    macro[0] = 30;    /* initialise macro */
  1954. X
  1955. X    page = 0;
  1956. X    new_page();
  1957. X}
  1958. X
  1959. Xvoid
  1960. Xset_option(option,value)
  1961. Xint *option;
  1962. Xchar *value;
  1963. X{
  1964. X    if (*value == '\0')
  1965. X        *option = !(*option);
  1966. X    else
  1967. X        *option = atoi(value);
  1968. X}
  1969. X
  1970. Xvoid
  1971. Xusage(str)
  1972. Xchar *str;
  1973. X{
  1974. X    fprintf(stderr,"Usage: %s [-L] [-R] [-c] [-d] [-e] [-lleft_margin]\n",
  1975. X        progname);
  1976. X    fprintf(stderr,"       [-ooutfile] [-q] [-s] [-tpaper_type] file\n");
  1977. X    fprintf(stderr,"%s\n",str);
  1978. X    exit(1);
  1979. X}
  1980. X
  1981. Xint
  1982. Xmain(argc,argv)
  1983. Xint argc;
  1984. Xchar *argv[];
  1985. X{
  1986. X    int i,j;
  1987. X    int ch;
  1988. X    infile = (FILE *)NULL;
  1989. X    outfile = stdout;
  1990. X    progname = argv[0];
  1991. X
  1992. X    for (i=1; i<argc; i++) {
  1993. X        if (argv[i][0] == '-') {
  1994. X        switch( argv[i][1] ) {
  1995. X            case 'L':
  1996. X                set_option(&auto_lf,&argv[i][2]);
  1997. X                break;
  1998. X            case 'R':
  1999. X                set_option(&auto_cr,&argv[i][2]);
  2000. X                break;
  2001. X            case 'c':
  2002. X                set_option(&condensed,&argv[i][2]);
  2003. X                break;
  2004. X            case 'd':
  2005. X                set_option(&debug,&argv[i][2]);
  2006. X                break;
  2007. X            case 'e':
  2008. X                set_option(&elite,&argv[i][2]);
  2009. X                break;
  2010. X            case 'l':
  2011. X                left = atoi(&argv[i][2]);
  2012. X                break;
  2013. X            case 'o':
  2014. X                if ( argv[i][2] == '\0' )
  2015. X                     usage("Need filename with -o option");
  2016. X                else if ( (outfile=fopen(&argv[i][2],"w")) 
  2017. X                        == (FILE *)NULL ) {
  2018. X                        fprintf(stderr,"Unable to open %s\n",
  2019. X                    &argv[i][2]);
  2020. X                    exit(1);
  2021. X                }
  2022. X                break;
  2023. X            case 'q':
  2024. X                set_option(&lq_mode,&argv[i][2]);
  2025. X                break;
  2026. X            case 's':
  2027. X                set_option(&screendump_mode,&argv[i][2]);
  2028. X                break;
  2029. X            case 't':
  2030. X              for (j=0; page_formats[j].name; j++) {
  2031. X                if (strcmp(&argv[i][2],page_formats[j].name)==0) {
  2032. X                  paper_type = j;
  2033. X                  break;
  2034. X                }
  2035. X              }
  2036. X              if (page_formats[j].name == (char *)NULL) {
  2037. X                  (void)strcpy(outline,"Valid paper types are:");
  2038. X                  for (j=0; page_formats[j].name; j++) {
  2039. X                (void)strcat(outline," ");
  2040. X                (void)strcat(outline,page_formats[j].name);
  2041. X                  }
  2042. X                  usage(outline);
  2043. X              }
  2044. X              break;
  2045. X            default:
  2046. X                (void)strcpy(outline,"Unknown option ");
  2047. X                (void)strcat(outline,argv[i]);
  2048. X                usage(outline);
  2049. X                break;
  2050. X        }
  2051. X        }
  2052. X        else {
  2053. X            if ((infile = fopen(argv[i],READBIN)) == (FILE *)NULL)  {
  2054. X            fprintf(stderr,"Unable to open %s\n",argv[i]);
  2055. X            exit(1);
  2056. X        }
  2057. X        }
  2058. X    }
  2059. X
  2060. X    if (infile == (FILE *)NULL)
  2061. X        usage("Need input filename");
  2062. X
  2063. X    /* open the prolog file */
  2064. X    if ((prologfile = fopen(prolog,"r")) == (FILE *)NULL)  {
  2065. X        /* try in same directory as epsonps.exe */
  2066. X        (void)strcpy(outline,argv[0]);
  2067. X        for (i=strlen(outline); i>0; i--) {
  2068. X            if (outline[i]=='\\' || outline[i]==':'
  2069. X                || outline[i]=='/' || outline[i]==']') {
  2070. X                (void)strcpy(&outline[i+1],prolog);
  2071. X                    prologfile = fopen(outline,"r");
  2072. X            break;
  2073. X            }
  2074. X        }
  2075. X        if (prologfile == (FILE *)NULL) {
  2076. X            fprintf(stderr,"Unable to open %s\n",prolog);
  2077. X            exit(1);
  2078. X        }
  2079. X        }
  2080. X
  2081. X    if ( (buffer=(char *)malloc(EPSONBUFSIZE)) == (char *)NULL ) {
  2082. X        fprintf(stderr,"%s: Unable to allocate memory\n",progname);
  2083. X        exit(1);
  2084. X    }
  2085. X
  2086. X    init_sets();
  2087. X    init_printer();
  2088. X#ifdef ANSI
  2089. X    (void)setvbuf(infile,buffer,_IOFBF,EPSONBUFSIZE);
  2090. X#endif
  2091. X    while ( (ch=getc(infile)) != EOF)
  2092. X        dochar((unsigned char)ch);
  2093. X    if (ptr>0)
  2094. X        putline();
  2095. X    if (cx > xstart || cy > ystart)
  2096. X        end_page();
  2097. X    else {
  2098. X        fputs("saveobj2 restore\n",outfile);
  2099. X        page--;
  2100. X    }
  2101. X    fputs("%%Trailer\n",outfile);
  2102. X    fprintf(outfile,"%%%%Pages: %d\n",page);
  2103. X    fputs("saveobj1 restore\n",outfile);
  2104. X    exit(0);
  2105. X    return(0);
  2106. X}
  2107. X/* end of epsonps.c */
  2108. END_OF_epsonps.c
  2109. if test 44784 -ne `wc -c <epsonps.c`; then
  2110.     echo shar: \"epsonps.c\" unpacked with wrong size!
  2111. fi
  2112. # end of overwriting check
  2113. fi
  2114. echo shar: End of shell archive.
  2115. exit 0
  2116.  
  2117. exit 0 # Just in case...
  2118. -- 
  2119. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2120. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2121. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2122. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2123.